package com.youaishujuhui.devops.web.util.db;

import java.io.IOException;

import org.springframework.web.socket.WebSocketSession;

import com.youaishujuhui.devops.web.service.SSHService;
import com.youaishujuhui.devops.web.util.WsUtil;

public class DbBakRemoteTask implements Runnable {
	private String ip;
	private int port;
	private SSHService sshService;
	private WebSocketSession wsSession;
	private String prefix;

	public DbBakRemoteTask(String ip, int port, SSHService sshService, WebSocketSession wsSession, String prefix) {
		this.ip = ip;
		this.port = port;
		this.sshService = sshService;
		this.wsSession = wsSession;
		this.prefix = prefix;
	}
	
	@Override
	public void run() {
		try {
			String cmd = "python /data/comm_sh/compress_file.py 2>&1";

	    	WsUtil.send(wsSession, prefix + ip, 
	    			"执行命令：" + cmd);
	    	
	    	sshService.exec(ip, port, cmd, wsSession, prefix);
		} catch (Exception e) {
			e.printStackTrace();
			try {
				WsUtil.send(wsSession, prefix + ip, 
						"出现异常：" + e.getMessage());
			} catch (IOException e1) {

			}
		}
		
	}

}
